package com.ziroom.finance.rabbitmq.producer;

import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.MessageProperties;
import com.ziroom.finance.rabbitmq.common.EndPoint;
import org.apache.commons.lang.SerializationUtils;


/**
 * The producer endpoint that writes to the queue.
 * @author syntx
 *
 */
public class Producer extends EndPoint {

    public Producer(String endPointName) throws IOException, TimeoutException {
        super(endPointName);
    }

    public void sendMessage(Serializable object) throws IOException {
        //消息持久化标识MessageProperties.PERSISTENT_TEXT_PLAIN
        //如果为null ,标识消息不持久化   不采用消息持久化，重启RabbitMQ服务后，消息队列存在，消息接收不到
        channel.basicPublish("",endPointName, MessageProperties.PERSISTENT_TEXT_PLAIN, SerializationUtils.serialize(object));
    }
}